package top.ed333.mcplugins.configurableevents;

import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

public class DependenciesResolver {
    private static boolean papiInstalled = false;
    private static boolean vaultInstalled = false;
    private static boolean playerPointsInstalled = false;

    public static void resolveDependencies() {
        Plugin papiPlugin = Bukkit.getPluginManager().getPlugin("PlaceholderAPI");
        Plugin vaultPlugin = Bukkit.getPluginManager().getPlugin("Vault");
        Plugin playerPointsPlugin = Bukkit.getPluginManager().getPlugin("PlayerPoints");

        papiInstalled = papiPlugin != null;
        vaultInstalled = vaultPlugin != null;
        playerPointsInstalled = playerPointsPlugin != null;

        if (papiInstalled) {
            ConsoleSender.info("&a检测到已安装了 PlaceholderAPI, 插件将会解析 PAPI 变量.");
        } else {
            ConsoleSender.warn("&e服务器未安装 PlaceholderAPI 插件, 插件将不会解析 PAPI 变量.");
        }

        if (playerPointsInstalled) {
            ConsoleSender.info("&a检测到已安装了 PlayerPoints 插件, 插件将会启用对 PlayerPoints 的支持.");
        } else {
            ConsoleSender.warn("&e服务器未安装 PlayerPoints 插件, 插件将不会启用对 PlayerPoints 的支持.");
        }

        if (vaultInstalled) {
            ConsoleSender.info("&a检测到已安装了 Vault 插件.");
            if (!VaultHelper.setupVault()) {
                ConsoleSender.warn("&e看起来这个服务器安装了 Vault 插件, 但是没有安装相关实现插件, 插件将不会启用对 Vault 的支持.");
                vaultInstalled = false;
            } else {
                ConsoleSender.info("&a插件将会启用对 Vault 的支持.");
            }
        } else {
            ConsoleSender.warn("&e服务器未安装 Vault 插件, 插件将不会启用对 Vault 的支持.");
        }
    }

    public static boolean isPapiInstalled() {
        return papiInstalled;
    }

    public static boolean isPlayerPointsInstalled() {
        return playerPointsInstalled;
    }

    public static boolean isVaultInstalled() {
        return vaultInstalled;
    }
}
